package androidgames.networkgames.screens;

import java.io.IOException;
import java.util.ArrayList;

import android.app.Dialog;
import android.content.pm.PackageInfo;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.os.Message;
import android.widget.PopupWindow;
import androidgames.configs.UIConfig;
import androidgames.networkgames.screens.components.BackgroundAnimation;
import androidgames.networkgames.screens.components.DrawableComponent;

import com.badlogic.androidgames.framework.Game;
import com.badlogic.androidgames.framework.Pixmap;
import com.badlogic.androidgames.framework.Sound;
import com.badlogic.androidgames.framework.Graphics.PixmapFormat;
import com.badlogic.androidgames.framework.impl.AndroidGame;

public class WelcomeScreen extends NetworkScreen {
	private Sound start = null;
	private BackgroundAnimation backgroundAnimetion;
	private int playtime = 0;
	private String ver;

	public WelcomeScreen(Game game) {
		super(game);
		// TODO Auto-generated constructor stub
		start = game.getAudio().newSound("Sounds/startup.mp3");
		ArrayList<Pixmap> listBG = new ArrayList<Pixmap>();
		listBG.add(g.newPixmap(UIConfig.LOGIN_BACKGROUND, PixmapFormat.RGB565));
		listBG.add(g.newPixmap("UI/background/black_cat.jpg",
				PixmapFormat.RGB565));
		backgroundAnimetion = new BackgroundAnimation(listBG);
		// nativeMenu.setItemWidth(30);
		background = backgroundAnimetion.getBackground();
		ver = checkVersion();
		System.out.print(ver);
	}

	@Override
	public void onDataReceive(byte[] data) throws IOException {
		// TODO Auto-generated method stub

	}

	@Override
	public void handlePacket(byte[] data) throws Exception {
		// TODO Auto-generated method stub

	}

	@Override
	public void addComponent(DrawableComponent component) {
		// TODO Auto-generated method stub

	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void present(float deltaTime) {
		// TODO Auto-generated method stub
		super.present(deltaTime);
		if (playtime < 20) {
			start.play(1);
			playtime++;
		} else if (playtime >= 20) {
			start.dispose();
		}
		background = backgroundAnimetion.getBackground();
		game.getGraphics().drawText(ver, 50, 50, Color.GREEN, 30, Style.FILL);// test
																				// only.
																				// disable
																				// later.
	}

	public String checkVersion() {
		PackageInfo pInfo = AndroidGame.packageInfo;
		String ver = "Version Name: " + pInfo.versionName.toString();
		ver += " - Version Code: " + pInfo.versionCode;
		return ver;
	}

	public void checData() {

	}

	public void downloadNewData() {

	}
}
